package com.ruoyi.develop.orderCommissionRecord.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.develop.orderCommissionRecord.domain.OrderCommissionRecord;
import com.ruoyi.develop.orderCommissionRecord.service.IOrderCommissionRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 订单提成记录Controller
 * @author lmm
 * @date 2024-11-14
 */
@RestController
@RequestMapping("/orderCommissionRecord/orderCommissionRecord")
public class OrderCommissionRecordController extends BaseController {
    @Autowired
    private IOrderCommissionRecordService orderCommissionRecordService;

    /**
     * 查询订单提成记录列表
     */
    @PreAuthorize("@ss.hasPermi('develop:OrderCommissionRecord:query')")
    @GetMapping("/list")
    public TableDataInfo list(OrderCommissionRecord entity) {
        startPage();
        List<OrderCommissionRecord> list = orderCommissionRecordService.selectList(entity);
        return getDataTable(list);
    }

    /**
     * 导出订单提成记录列表
     */
    @PreAuthorize("@ss.hasPermi('develop:OrderCommissionRecord:export')")
    @Log(title = "订单提成记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderCommissionRecord entity) {
        List<OrderCommissionRecord> list = orderCommissionRecordService.selectList(entity);
        ExcelUtil<OrderCommissionRecord> util = new ExcelUtil<OrderCommissionRecord>(OrderCommissionRecord. class);
        util.exportExcel(response, list, "订单提成记录数据");
    }

    /**
     * 获取订单提成记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('develop:OrderCommissionRecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(orderCommissionRecordService.selectById(id));
    }


    /**
     * 获取订单提成记录详细信息
     */
    @GetMapping(value = "/getByOrderId/{orderId}")
    public AjaxResult getByOrderId(@PathVariable("orderId") String orderId) {

        OrderCommissionRecord record = orderCommissionRecordService.selectByOrderId(orderId);

        return AjaxResult.success(record);
    }





    /**
     * 新增订单提成记录
     */
    @PreAuthorize("@ss.hasPermi('develop:OrderCommissionRecord:add')")
    @Log(title = "订单提成记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody OrderCommissionRecord entity) {
        List<OrderCommissionRecord> recordList = orderCommissionRecordService.selectList(entity);
        if(!recordList.isEmpty()){
            return AjaxResult.error("订单提成记录已存在");
        }
        return toAjax(orderCommissionRecordService.insert(entity));
    }

    /**
     * 修改订单提成记录
     */
    @PreAuthorize("@ss.hasPermi('develop:OrderCommissionRecord:edit')")
    @Log(title = "订单提成记录", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody OrderCommissionRecord entity) {
        return toAjax(orderCommissionRecordService.update(entity));
    }

    /**
     * 删除订单提成记录
     */
    @PreAuthorize("@ss.hasPermi('develop:OrderCommissionRecord:remove')")
    @Log(title = "订单提成记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(orderCommissionRecordService.deleteByIds(ids));
    }
}
